<?php

/*

My Shop (myshop.php)

*/

$page_title = "My Shop";
$rank_check = 1;
include "header.inc.php";

print "$openHTML";

$find_shop = fetch("SELECT * FROM usershops2 WHERE owner = '$userid' AND game = '$game'");

if (!$find_shop[id])
{
	die("You do not have a shop yet, please click <a href=makeshop.php?game=$game>here</a> to create one.$closeHTML");
}

$sum_items = mysql_query("SELECT sum(stock) AS stock FROM usershops_items2 WHERE owner = '$userid' AND game = '$game'");
$sum_items2 = mysql_fetch_array($sum_items);
$max_stock = $find_shop[shop_size] * 5;

ECHO <<<END

<p align=center><a href=myshop.php?game=$game>My Stock</a> | <a href=myitems.php?game=$game>My Items</a> | <a href=edit_shop.php?game=$game>Edit Shop</a> | <a href=usershop.php?game=$game&user=$username>View Shop</a> | <a href=upgrade_shop.php?game=$game>Upgrade Shop</a> | <a href=sales_log.php?game=$game>Sales Log</a></p>

<form action=myshop.pro.php?game=$game method=post>
<CENTER><FONT SIZE="-1"><B>You have $sum_items2[stock]
items in stock, with a max of $max_stock.</B></FONT>

<P><FONT SIZE="-1"><TABLE CELLSPACING=1 CELLPADDING=0 WIDTH="95%" BGCOLOR="$topAndBottomBG">
   <TR BGCOLOR="$topAndBottomBG">
      <TD COLSPAN=6 HEIGHT=45>
         <CENTER><FONT SIZE="+2" COLOR="$topAndBottomText">--My
         Shop--</FONT></CENTER>
      </TD>
   </TR><form action=myshop.php?game=$game&page=update_prices method=post>
   <TR BGCOLOR="$topAndBottomBG">
      <TD WIDTH=85>
         <CENTER><FONT SIZE="-1">Image</FONT></CENTER>
      </TD>
      <TD WIDTH=90>
         <CENTER><FONT SIZE="-1">Name/Price</FONT></CENTER>
      </TD>
      <TD WIDTH=45>
         <CENTER><FONT SIZE="-1">Stock</FONT></CENTER>
      </TD>
      <TD WIDTH=55>
         <CENTER><FONT SIZE="-1">Value</FONT></CENTER>
      </TD>
      <TD>
         <CENTER><FONT SIZE="-1">Descrition</FONT></CENTER>
      </TD>
      <TD WIDTH=100>
         <CENTER><FONT SIZE="-1">Remove</FONT></CENTER>
      </TD>
   </TR>

END;

$find_items2 = mysql_query("SELECT * FROM usershops_items2 WHERE owner = '$userid' AND game = '$game'");
$numItems = mysql_num_rows($find_items2);

$z = 1;

while ($find_items = mysql_fetch_array($find_items2))
{
	$find_item2 = mysql_fetch_array(mysql_query("SELECT * FROM items2 WHERE id = 	'$find_items[item_id]' AND game = '$game'"));
	$id = $find_items[id];

	if ($numItems <= 100) { $description = "$find_item2[item_desc]"; } else { $description = "<font size=+2 color=blue>*</font>"; }

	print "<TR BGCOLOR=\"$maincellColor\">
      <TD WIDTH=85>
         <CENTER><IMG SRC=\"images/user_images/opg_$game/items/item_$find_item2[id].gif\"></CENTER>
      </TD>
      <TD WIDTH=90>
         <CENTER><FONT SIZE=\"-1\"><B>$find_item2[item_name]</B></FONT><BR>
         <INPUT TYPE=text NAME=\"item_price[$id]\" VALUE=\"$find_items[price]\" SIZE=7 MAXLENGTH=6></CENTER>
      </TD>
      <TD WIDTH=45>
         <CENTER><FONT SIZE=\"-1\">$find_items[stock]</FONT></CENTER>
      </TD>
      <TD WIDTH=55>
         <CENTER><FONT SIZE=\"-1\">$find_item2[item_value]</FONT></CENTER>
      </TD>
      <TD>
         <P><FONT SIZE=\"-1\">$description</FONT></P>
      </TD>
      <TD WIDTH=100>
         <CENTER><FONT SIZE=\"-1\">Remove:
         <INPUT TYPE=text NAME=\"remove[$id]\" VALUE=\"0\" SIZE=7 MAXLENGTH=6><BR>
         item(s)</FONT></CENTER>
      </TD>
   </TR>";
}

ECHO <<<ENDED
</TABLE>
 <INPUT TYPE=submit NAME=Submit VALUE="Update Stock"></FONT></P></CENTER></form>

<p><font size=-1>* - DescriptionStop blocks descriptions from being displayed if there are more then 100 items in your shop or gallery, this is to cut back load time for big shops.</font></p>

ENDED;

print "$closeHTML";
?>
